class Solution(object):
    def isValid(self,s) :
        stack = []
        mapping = {')': '(', '}': '{', ']': '['}
        for char in s:
            if char in mapping:  # 当前字符是右括号
                top_element = stack.pop() if stack else '#'  # 栈空则取特殊标记
                if mapping[char] != top_element:
                    return False
            else:  # 当前字符是左括号
                stack.append(char)

        return not stack  # 栈空则所有括号正确闭合

print(Solution().isValid("([])"))
